package it.gat.webservice.resource.impl;

import java.sql.SQLException;
import java.util.List;

import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

import it.gat.dao.ContrattoDAO;
import it.gat.model.Contratto;
import it.gat.util.dao.DAOFactory;
import it.gat.webservice.utils.Impostazioni;

public class ContrattiClientiResource extends ServerResource{
	
	@Get
	public Contratto[] retriveByCliente() {
		DAOFactory daoFactory = DAOFactory.getDAOFactory(Integer.parseInt(Impostazioni.getProperty("DB_TYPE")));
		ContrattoDAO contrattoDAO = daoFactory.getContrattoDAO();
		List<Contratto> contratti;
		try {
			contratti = contrattoDAO.retrieveByIdCliente(Integer.parseInt(getRequestAttributes().get("id").toString()));
		} catch (NumberFormatException e) {
			return null;
		} catch (SQLException e) {
			return null;
		}
		return contratti.toArray(new Contratto[0]);
	}

}
